# APKBUILD based on linux-vanilla aport. Changes:
# - disabled module installation
# - add !check !tracedeps
# - package: just install zimage and kernel.release, because the kernel config
# does not generate modules or dtb files
# - do not create -dev subpackage (makes no sense without module support)
#
# Kernel config changes, based on: arch/arm/configs/cyanogenmod_dlx_defconfig
# - enable devtmpfs (needed for udev -> touch support in weston)

_vendor=htc
_flavor=htc-dlx
_hash="f6eb6496406f5a06cdd4716e494082d78df70e83"
_config="config-${_flavor}.armhf"

pkgname=linux-${_flavor}
pkgver=3.4.0
case $pkgver in
*.*.*)  _kernver=${pkgver%.*};;
*.*) _kernver=$pkgver;;
esac
pkgrel=10
arch="armhf"
pkgdesc="HTC Droid DNA kernel from LineageOS"
url="https://github.com/LineageOS/android_device_htc_dlx"
depends="postmarketos-mkinitfs"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev xz"
options="!strip !check !tracedeps"
install=
source="
$pkgname-$_hash.zip::https://github.com/LineageOS/android_kernel_htc_m7/archive/${_hash}.zip
$_config
compiler-gcc6.h
gcc-fix.patch
make-fix.patch
bcmdhd-remove-Werror.patch
gpu-msm2-fix-gcc5-compile.patch
"
subpackages=""
license="GPL2"

_abi_release=${pkgver}
_carch="arm"
HOSTCC="${CC:-gcc}"
HOSTCC="${HOSTCC#${CROSS_COMPILE}}"

ksrcdir="$srcdir/android_kernel_htc_m7-${_hash}"

prepare() {
        local _patch_failed=
                cd "$ksrcdir"

# first apply patches in specified order
                for i in $source; do
                        case $i in
                                *.patch)
                                msg "Applying $i..."
                                if ! patch -s -p1 -N -i "$srcdir"/$i; then
                                        echo $i >>failed
                                                _patch_failed=1
                                                fi
                                                ;;
        esac
                done

                if ! [ -z "$_patch_failed" ]; then
                        error "The following patches failed:"
                                cat failed
                                return 1
                                fi

# gcc6 support
                                cp -v "$srcdir/compiler-gcc6.h" "$ksrcdir/include/linux/"

                                mkdir -p "$srcdir"/build
                                cp "$srcdir"/$_config "$srcdir"/build/.config || return 1
                                make -C "$ksrcdir" O="$srcdir"/build ARCH="$_carch" HOSTCC="$HOSTCC" \
                                silentoldconfig
}



# this is so we can do: 'abuild menuconfig' to reconfigure kernel
menuconfig() {
        cd "$srcdir"/build || return 1
                make ARCH="$_carch" menuconfig
                cp .config "$startdir"/$_config
}

build() {
        cd "$srcdir"/build
                unset LDFLAGS
                make ARCH="$_carch" CC="${CC:-gcc}" \
                KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \
                || return 1
}

package() {
        install -Dm644 "$srcdir/build/arch/arm/boot/zImage" \
                "$pkgdir/boot/vmlinuz-$_flavor"

                install -D "$srcdir/build/include/config/kernel.release" \
                "$pkgdir/usr/share/kernel/$_flavor/kernel.release"
}

sha512sums="3b6ea5971f4644509df3f9962963d42ed9aea04a4d1856a87515198e92a99eef12d7882e27f6eba3e9f7929e2fa491f1b6cc98045e2a93673e58cd0ad70681ca  linux-htc-dlx-f6eb6496406f5a06cdd4716e494082d78df70e83.zip
30e08ec1ebda5bec8581c4c5b84bf89c8344fdb86988a5b56dfae193c321c2249dfa54f732c3906a19d10a17b66e829684de7679852a0263ea273e813582913f  config-htc-dlx.armhf
d80980e9474c82ba0ef1a6903b434d8bd1b092c40367ba543e72d2c119301c8b2d05265740e4104ca1ac5d15f6c4aa49e8776cb44264a9a28dc551e0d1850dcc  compiler-gcc6.h
5a19ccc419263f192fa74f15f11c2e920e6fa39ccab4e8881ed0e674cf2c368220f14667329eb5384ac4cea3e045d10a9b8f1de4bce8f21dc76484f920510b6f  gcc-fix.patch
17af4b972e8bbf3fe9d0597efabe1a3611875daaaeaab3b82837c91ea3197493eefec77e5d59962295bf3dad4dbe28fa9cef98eb51afc93faef8f488a9c4bfe7  make-fix.patch
cb80c3dd3d68d59939ad2b6c66c8bde3148df2dda96ba4fcdd87937101f312ff313abc12048e71deda23376a524b46daf6af5e32cd203d099825c08dba9a24c7  bcmdhd-remove-Werror.patch
01c48eb7ae59338bcdad79c5005d4e543d1245a5f9050cf6f80ff00d522ec1f47763cc66a6feb6db0359c4cf693c8ce4c6fcb8c83e7011f59564b0dc741de9f2  gpu-msm2-fix-gcc5-compile.patch"
